package com.taraslaba.polvisachecker.server;

import java.util.Date;
import java.util.logging.Logger;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Transaction;

public class ScheduleInfoHistoryDatastore {
	private static final DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
	private static final Logger logger = Logger.getLogger(ScheduleInfoHistoryDatastore.class.getName());
	
	private static final String SCHEDULE_HISTORY_TYPE = "ScheduleHistory";
	private static final String DATE = "date";
	private static final String MESSAGE = "message";
	
	public static void logScheduleInfo(String message) {
		logger.entering(ScheduleInfoHistoryDatastore.class.getName(), "logScheduleInfo", message);
		
		Transaction tnx = datastore.beginTransaction();
		try {
			Entity entity = new Entity(SCHEDULE_HISTORY_TYPE);
			entity.setProperty(MESSAGE, message);
			entity.setProperty(DATE, new Date());
			datastore.put(entity);
			tnx.commit();
		}
		finally {
			if(tnx.isActive()){
				tnx.rollback();
			}
		}
		
		logger.exiting(ScheduleInfoHistoryDatastore.class.getName(), "logScheduleInfo");
	}
}
